#include "head.h"
//后续记得用libvlc的事件机制和openGL再度优化它

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    auto screen = QGuiApplication::primaryScreen();
    auto WH = screen->geometry();
    setGeometry((WH.width() - MAINWIDGET_WIDTH)/2, (WH.height() - MAINWIDGET_HEIGHT)/2, MAINWIDGET_WIDTH, MAINWIDGET_HEIGHT);
    setAutoFillBackground(true);
    setFixedSize(MAINWIDGET_WIDTH, MAINWIDGET_HEIGHT);
    loadWidget();
}

void  Widget::acceptmusicInformation(QString songName,QString artist)
{
    _musicInformation->setText(songName, artist);
}


void Widget::loadWidget()
{
    _verticalLayout = new QVBoxLayout();
    _verticalLayout->setContentsMargins(0, 0, 0, 0);
//    _verticalLayout->setGeometry(QRect(VerticalX, VerticalY, Vertical_WIDTH, Vertical_HEIGHT));

    _verticalLayout->setSpacing(0);
//    _verticalLayout->setAlignment(Qt::AlignTop);

    _horizontalLayput = new QHBoxLayout();
    _verticalLayout->addLayout(_horizontalLayput);
//    _horizontalLayput->setGeometry(QRect(0, 0, horizontalWIDTH, horizontalHEIGHT));被嵌套的布局大小是无法设置，大小是自适应的
    _horizontalLayput->setContentsMargins(10, 30, 10, 16);
//    _horizontalLayput->setAlignment(Qt::AlignTop);


    _topButtonLeft = new QPushButton();
    _topButtonLeft->setFlat(true);
    _topButtonLeft->setStyleSheet("background-color:transparent;");
    _topButtonLeft->resize(TOPBUTTON_WIDTH, TOPBUTTON_HEIGHT);
    _topButtonLeft->setIcon(QPixmap(":/images/Resources/backButton.png"));
    _topButtonLeft->setIconSize(QSize(TOPBUTTON_WIDTH, TOPBUTTON_HEIGHT));

    _horizontalLayput->addWidget(_topButtonLeft, 0, Qt::AlignLeft);
//    _horizontalLayput->setStretchFactor(_topButtonLeft, 1);

    _musicInformation = new TopWidget();
    _horizontalLayput->addWidget(_musicInformation, 0/*, Qt::AlignCenter*/);//不能居中会消失，为什么？或许是另外两个都选了对齐方式，所以这个给它留余量？
    _musicInformation->resize(TOPBUTTON_WIDTH, TOPBUTTON_HEIGHT);
    _musicInformation->setText("", "");
//    _horizontalLayput->setStretchFactor(_musicInformation, 1);


    _topButtonRight = new QPushButton();
    _topButtonRight->setFlat(true);
    _topButtonRight->setStyleSheet("background-color:transparent;");
    _topButtonRight->resize(TOPBUTTON_WIDTH, TOPBUTTON_HEIGHT);
    _topButtonRight->setIcon(QPixmap(":/images/Resources/musicListButton.png"));
    _topButtonRight->setIconSize(QSize(TOPBUTTON_WIDTH, TOPBUTTON_HEIGHT));

    _horizontalLayput->addWidget(_topButtonRight, 0, Qt::AlignRight);
//    _horizontalLayput->setStretchFactor(_topButtonRight, 1);

    _musicPlayer = new MusicPlayer();
    connect(_musicPlayer, SIGNAL(sendMusicInformationToTop(QString, QString)), this, SLOT(acceptmusicInformation(QString,QString)));
    _verticalLayout->addWidget(_musicPlayer, 0);

    setLayout(_verticalLayout);
}



void Widget::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPixmap picture(":/images/Resources/musicPlayerPageBg.png");
    QPainter painter(this);
    painter.save();
    painter.setRenderHints(QPainter::SmoothPixmapTransform|QPainter::Antialiasing, true);
    painter.drawPixmap(rect(), picture, picture.rect());
    painter.restore();
}

Widget::~Widget()
{
}

